package com.neuedu.web;

import com.neuedu.service.ArticleService;
import com.neuedu.service.ArticleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "GoIndexServlet",urlPatterns = "/go/index")
public class GoIndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 查询首页信息（文章，榜单等）
        ArticleService articleService = new ArticleServiceImpl();
        // 首页非置顶文章信息
        List<Map<String,Object>> list = articleService.getIndexArticleInfo();
        request.setAttribute("articleList",list);
        // 首页置顶文章信息
        List<Map<String,Object>> list2 = articleService.getTopArticleInfo();
        request.setAttribute("topArticleList",list2);
        // 转发首页
        request.getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(request,response);
    }
}
